//
//  CoursesSearchViewController.m
//  classroom
//
//  Created by apple on 12-10-28.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CoursesSearchViewController.h"
#import "PopoverTableViewController.h"
#import "CoursesDetailViewController.h"
#import "FPPopoverController.h"
@interface CoursesSearchViewController ()

@end

@implementation CoursesSearchViewController
@synthesize searchConditions;
@synthesize searchtableView;
@synthesize searchResultDic;
@synthesize nameResult;
@synthesize searchConditionsDic,searchResultDic1,searchResultDic2,searchResultDic3,searchResultDic4;
@synthesize name,price;
@synthesize storyboard;
@synthesize choise;

@synthesize searchResultDic111,searchResultDic112,searchResultDic121,searchResultDic122,searchResultDic211,searchResultDic212,searchResultDic221,searchResultDic222;
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.choise=1;
	// Do any additional setup after loading the view, typically from a nib.
    
  //    searchResultDic=[[NSMutableDictionary alloc]init];
//    nameResult=[[NSMutableArray alloc]init];
//    NSMutableArray *cet4=[[NSMutableArray alloc]initWithObjects:@"大望路新东方四级", @"朝阳老罗四级英语",@"轻松搞定四级单词",nil];
//    [searchResultDic setObject:cet4 forKey:@"四级"];
//    
//    NSMutableArray *cet6=[[NSMutableArray alloc]initWithObjects:@"大望路新东方六级", @"朝阳老罗六级英语",@"轻松六级单词",nil];
//    [searchResultDic setObject:cet6 forKey:@"六级"];
//    NSMutableArray *graduate=[[NSMutableArray alloc]initWithObjects:@"大望路太奇考研英语", @"新东方考研英语",@"轻松搞定考研单词",nil];
//    [searchResultDic setObject:graduate forKey:@"考研英语"];
//    
//    for (int i=0; i<[cet4 count]; i++) {
//        [nameResult addObject:[cet4 objectAtIndex:i]];
//    }
//    for (int i=0; i<[cet6 count]; i++) {
//        [nameResult addObject:[cet6 objectAtIndex:i]];
//    }
//    
//    for (int i=0; i<[graduate count]; i++) {
//        [nameResult addObject:[graduate objectAtIndex:i]];
//    }
//    
//    
    [self initDictions];
    [self setCellArray];
    searchtableView=[[UITableView alloc]initWithFrame:CGRectMake(20, 92, 280, 298) style:UITableViewStylePlain];
    searchtableView.layer.cornerRadius = 6;
    searchtableView.layer.masksToBounds = YES;
    [searchtableView setDelegate:self];
    [searchtableView setDataSource:self];
    [self.view addSubview:searchtableView];
    
    
    
  
 
}

- (void)viewDidUnload
{
    [self setSearchtableView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    
    
}

-(void)initDictions
{
    self.searchConditionsDic=[[NSMutableDictionary alloc]init];
    
   
    self.name=[[NSMutableArray alloc]init];
    self.price=[[NSMutableArray alloc]init];
    [self.searchConditionsDic setObject:@"全部" forKey:@"类型"];
    [self.searchConditionsDic setObject:@"全部" forKey:@"价格"];
    [self.searchConditionsDic setObject:@"全部" forKey:@"地区"];
    
    searchConditions=[[NSMutableDictionary alloc]init];
    NSMutableArray* coursesType=[[NSMutableArray alloc]initWithObjects:@"四级",@"六级", @"全部",nil];
    NSMutableArray* coursesPrice=[[NSMutableArray alloc]initWithObjects:@"500",@"999",@"全部",nil];
    NSMutableArray* coursesArea=[[NSMutableArray alloc]initWithObjects:@"朝阳",@"海淀",@"全部",nil];
    NSLog(@"coursesArea=%@",coursesArea);
    [searchConditions setObject:coursesType forKey:@"coursesType"];
    [searchConditions setObject:coursesPrice forKey:@"coursesPrice"];
    [searchConditions setObject:coursesArea forKey:@"coursesArea"];
    
    [self initTestDate];
    
}
-(void)initTestDate
{
    self.searchResultDic111=[[NSMutableDictionary alloc]init];
    self.searchResultDic112=[[NSMutableDictionary alloc]init];
    self.searchResultDic121=[[NSMutableDictionary alloc]init];
    self.searchResultDic122=[[NSMutableDictionary alloc]init];
    self.searchResultDic211=[[NSMutableDictionary alloc]init];
    self.searchResultDic212=[[NSMutableDictionary alloc]init];
    self.searchResultDic221=[[NSMutableDictionary alloc]init];
    self.searchResultDic222=[[NSMutableDictionary alloc]init];

    
        
    NSMutableDictionary *dic1111=[[NSMutableDictionary alloc]init];
    [dic1111 setObject:@"1111" forKey:@"InfoID"];
    [dic1111 setObject:@"新北方四级" forKey:@"CoureName"];
    [dic1111 setObject:@"480" forKey:@"Price"];
    [dic1111 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic111 setObject:dic1111 forKey:@"1111"];
    NSMutableDictionary *dic1112=[[NSMutableDictionary alloc]init];
    [dic1112 setObject:@"1112" forKey:@"InfoID"];
    [dic1112 setObject:@"考级网四级" forKey:@"CoureName"];
    [dic1112 setObject:@"499" forKey:@"Price"];
    [dic1112 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic111 setObject:dic1112 forKey:@"1112"];
    NSMutableDictionary *dic1113=[[NSMutableDictionary alloc]init];
    [dic1113 setObject:@"1113" forKey:@"InfoID"];
    [dic1113 setObject:@"包过四级" forKey:@"CoureName"];
    [dic1113 setObject:@"478" forKey:@"Price"];
    [dic1113 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic111 setObject:dic1113 forKey:@"1113"];
    
    
    NSMutableDictionary *dic1121=[[NSMutableDictionary alloc]init];
    [dic1121 setObject:@"1121" forKey:@"InfoID"];
    [dic1121 setObject:@"新北方四级" forKey:@"CoureName"];
    [dic1121 setObject:@"480" forKey:@"Price"];
    [dic1121 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic112 setObject:dic1121 forKey:@"1121"];
    NSMutableDictionary *dic1122=[[NSMutableDictionary alloc]init];
    [dic1122 setObject:@"1122" forKey:@"InfoID"];
    [dic1122 setObject:@"考级网四级" forKey:@"CoureName"];
    [dic1122 setObject:@"499" forKey:@"Price"];
    [dic1122 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic112 setObject:dic1122 forKey:@"1122"];
    NSMutableDictionary *dic1123=[[NSMutableDictionary alloc]init];
    [dic1123 setObject:@"1123" forKey:@"InfoID"];
    [dic1123 setObject:@"包过四级" forKey:@"CoureName"];
    [dic1123 setObject:@"468" forKey:@"Price"];
    [dic1123 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic112 setObject:dic1123 forKey:@"1123"];
    
    
    NSMutableDictionary *dic1211=[[NSMutableDictionary alloc]init];
    [dic1211 setObject:@"1211" forKey:@"InfoID"];
    [dic1211 setObject:@"新北方四级" forKey:@"CoureName"];
    [dic1211 setObject:@"680" forKey:@"Price"];
    [dic1211 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic121 setObject:dic1211 forKey:@"1211"];
    NSMutableDictionary *dic1212=[[NSMutableDictionary alloc]init];
    [dic1212 setObject:@"1212" forKey:@"InfoID"];
    [dic1212 setObject:@"考级网四级" forKey:@"CoureName"];
    [dic1212 setObject:@"599" forKey:@"Price"];
    [dic1212 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic121 setObject:dic1212 forKey:@"1212"];
    NSMutableDictionary *dic1213=[[NSMutableDictionary alloc]init];
    [dic1213 setObject:@"1213" forKey:@"InfoID"];
    [dic1213 setObject:@"包过四级" forKey:@"CoureName"];
    [dic1213 setObject:@"700" forKey:@"Price"];
    [dic1213 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic121 setObject:dic1213 forKey:@"1213"];
    
    
    NSMutableDictionary *dic1221=[[NSMutableDictionary alloc]init];
    [dic1221 setObject:@"1221" forKey:@"InfoID"];
    [dic1221 setObject:@"新北方四级" forKey:@"CoureName"];
    [dic1221 setObject:@"780" forKey:@"Price"];
    [dic1221 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic122 setObject:dic1221 forKey:@"1221"];
    NSMutableDictionary *dic1222 =[[NSMutableDictionary alloc]init];
    [dic1222 setObject:@"1222" forKey:@"InfoID"];
    [dic1222 setObject:@"考级网四级" forKey:@"CoureName"];
    [dic1222 setObject:@"699" forKey:@"Price"];
    [dic1222 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic122 setObject:dic1222 forKey:@"1222"];
    NSMutableDictionary *dic1223=[[NSMutableDictionary alloc]init];
    [dic1223 setObject:@"1223" forKey:@"InfoID"];
    [dic1223 setObject:@"包过四级" forKey:@"CoureName"];
    [dic1223 setObject:@"768" forKey:@"Price"];
    [dic1223 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic122 setObject:dic1223 forKey:@"1223"];
    
    
    
    NSMutableDictionary *dic2111=[[NSMutableDictionary alloc]init];
    [dic2111 setObject:@"2111" forKey:@"InfoID"];
    [dic2111 setObject:@"新北方六级" forKey:@"CoureName"];
    [dic2111 setObject:@"480" forKey:@"Price"];
    [dic2111 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic211 setObject:dic2111 forKey:@"2111"];
    NSMutableDictionary *dic2112=[[NSMutableDictionary alloc]init];
    [dic2112 setObject:@"2112" forKey:@"InfoID"];
    [dic2112 setObject:@"考级网六级" forKey:@"CoureName"];
    [dic2112 setObject:@"499" forKey:@"Price"];
    [dic2112 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic211 setObject:dic2112 forKey:@"2112"];
    NSMutableDictionary *dic2113=[[NSMutableDictionary alloc]init];
    [dic2113 setObject:@"2113" forKey:@"InfoID"];
    [dic2113 setObject:@"包过六级" forKey:@"CoureName"];
    [dic2113 setObject:@"478" forKey:@"Price"];
    [dic2113 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic211 setObject:dic2113 forKey:@"2113"];
    
    
    NSMutableDictionary *dic2121=[[NSMutableDictionary alloc]init];
    [dic2121 setObject:@"2121" forKey:@"InfoID"];
    [dic2121 setObject:@"新北方六级" forKey:@"CoureName"];
    [dic2121 setObject:@"480" forKey:@"Price"];
    [dic2121 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic212 setObject:dic2121 forKey:@"2121"];
    NSMutableDictionary *dic2122=[[NSMutableDictionary alloc]init];
    [dic2122 setObject:@"2122" forKey:@"InfoID"];
    [dic2122 setObject:@"考级网六级" forKey:@"CoureName"];
    [dic2122 setObject:@"499" forKey:@"Price"];
    [dic2122 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic212 setObject:dic2122 forKey:@"2122"];
    NSMutableDictionary *dic2123=[[NSMutableDictionary alloc]init];
    [dic2123 setObject:@"2123" forKey:@"InfoID"];
    [dic2123 setObject:@"包过六级" forKey:@"CoureName"];
    [dic2123 setObject:@"468" forKey:@"Price"];
    [dic2123 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic212 setObject:dic2123 forKey:@"2123"];
    
    
    NSMutableDictionary *dic2211=[[NSMutableDictionary alloc]init];
    [dic2211 setObject:@"2211" forKey:@"InfoID"];
    [dic2211 setObject:@"新北方六级" forKey:@"CoureName"];
    [dic2211 setObject:@"680" forKey:@"Price"];
    [dic2211 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic221 setObject:dic2211 forKey:@"2211"];
    NSMutableDictionary *dic2212=[[NSMutableDictionary alloc]init];
    [dic2212 setObject:@"2212" forKey:@"InfoID"];
    [dic2212 setObject:@"考级网六级" forKey:@"CoureName"];
    [dic2212 setObject:@"599" forKey:@"Price"];
    [dic2212 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic221 setObject:dic2212 forKey:@"2212"];
    NSMutableDictionary *dic2213=[[NSMutableDictionary alloc]init];
    [dic2213 setObject:@"2213" forKey:@"InfoID"];
    [dic2213 setObject:@"包过六级" forKey:@"CoureName"];
    [dic2213 setObject:@"700" forKey:@"Price"];
    [dic2213 setObject:@"朝阳" forKey:@"Area"];
    [self.searchResultDic221 setObject:dic2213 forKey:@"2213"];
    
    NSMutableDictionary *dic2221=[[NSMutableDictionary alloc]init];
    [dic2221 setObject:@"2221" forKey:@"InfoID"];
    [dic2221 setObject:@"新北方六级" forKey:@"CoureName"];
    [dic2221 setObject:@"780" forKey:@"Price"];
    [dic2221 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic222 setObject:dic2221 forKey:@"2221"];
    NSMutableDictionary *dic2222 =[[NSMutableDictionary alloc]init];
    [dic2222 setObject:@"2222" forKey:@"InfoID"];
    [dic2222 setObject:@"考级网六级" forKey:@"CoureName"];
    [dic2222 setObject:@"699" forKey:@"Price"];
    [dic2222 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic222 setObject:dic2222 forKey:@"2222"];
    NSMutableDictionary *dic2223=[[NSMutableDictionary alloc]init];
    [dic2223 setObject:@"2223" forKey:@"InfoID"];
    [dic2223 setObject:@"包过六级" forKey:@"CoureName"];
    [dic2223 setObject:@"768" forKey:@"Price"];
    [dic2223 setObject:@"海淀" forKey:@"Area"];
    [self.searchResultDic222 setObject:dic2223 forKey:@"2223"];
    
}

-(int)getDate
{
    
    NSString *typeStr=(NSString *)[self.searchConditionsDic objectForKey:@"类型"];
    NSString *priceStr=[self.searchConditionsDic objectForKey:@"价格"];
    NSString *areaStr=[self.searchConditionsDic objectForKey:@"地区"];
    //以下代码可以改成将button的title取出放入字典，
    //然后用字典向服务器发送请求，而后接收到的数据转换成字典，解析分别放入不同的NSArray中， 如：idArray，nameArray，intreduceArray，scoresarray等
    //用NSArray 生成tableviewcell，并通过 点击tableviewcell，获取点击的index.row从idArray找到对应的id，向服务器请求~并获取信息，放入detail页面中
    //
    int a,b,c;
    
    if ([typeStr isEqualToString:@"全部"])
    {
        a=300;
    }else if([typeStr isEqualToString:@"四级"]){
        a=100;
    }else if([typeStr isEqualToString:@"六级"]){
        a=200;
    }
    
    if ([priceStr isEqualToString:@"全部"])
    {
        b=30;
    }else if([priceStr isEqualToString:@"500"]){
        b=10;
    }else if([priceStr isEqualToString:@"999"]){
        b=20;
    }
    
    
    if ([areaStr isEqualToString:@"全部"])
    {
        c=3;
    }else if([areaStr isEqualToString:@"朝阳"]){
        c=1;
    }else if([areaStr isEqualToString:@"海淀"]){
        c=2;
    }
    
    
    
    return a+b+c;
    
    
//    if ([typeStr isEqualToString:@"全部"]) {
//        if ([priceStr isEqualToString:@"全部"]) {
//            if ([areaStr isEqualToString:@"全部"]) {
//                return 333;
//            }else if([areaStr isEqualToString:@"朝阳"]) {
//                return 331;
//            }else if([areaStr isEqualToString:@"海淀"]) {
//                return 332;
//            }
//
//        }else if([priceStr isEqualToString:@"500"]){
//            if([areaStr isEqualToString:@"全部"])
//            {
//                return 313;
//            }else if([areaStr isEqualToString:@"朝阳"]) {
//                return 311;
//            }else if([areaStr isEqualToString:@"海淀"]) {
//                return 312;
//            }
//        }else if([priceStr isEqualToString:@"999"]){
//            if([areaStr isEqualToString:@"全部"])
//            {
//                return 323;
//            }else if([areaStr isEqualToString:@"朝阳"]) {
//                return 321;
//            }else if([areaStr isEqualToString:@"海淀"]) {
//                return 322;
//            }
//
//        }
//    }//else if([typeStr isEqualToString:@"四级"]) {
//            if ([priceStr isEqualToString:@"全部"]) {
//                if ([areaStr isEqualToString:@"全部"]) {
//                    return 133;
//                }else if([areaStr isEqualToString:@"朝阳"]) {
//                    return 131;
//                }else if([areaStr isEqualToString:@"海淀"]) {
//                    return 132;
//                }
//                
//            }else if([priceStr isEqualToString:@"500"]){
//                if([areaStr isEqualToString:@"全部"])
//                {
//                    return 113;
//                }else if([areaStr isEqualToString:@"朝阳"]) {
//                    return 111;
//                }else if([areaStr isEqualToString:@"海淀"]) {
//                    return 112;
//                }
//            }else if([priceStr isEqualToString:@"999"]){
//                if([areaStr isEqualToString:@"全部"])
//                {
//                    return 123;
//                }else if([areaStr isEqualToString:@"朝阳"]) {
//                    return 121;
//                }else if([areaStr isEqualToString:@"海淀"]) {
//                    return 122;
//                }
//    
//            }
//    }else if([typeStr isEqualToString:@"六级"]) {
//                if ([priceStr isEqualToString:@"全部"]) {
//                    if ([areaStr isEqualToString:@"全部"]) {
//                        return 233;
//                    }else if([areaStr isEqualToString:@"朝阳"]) {
//                        return 231;
//                    }else if([areaStr isEqualToString:@"海淀"]) {
//                        return 232;
//                    }
//                    
//                }else if([priceStr isEqualToString:@"500"]){
//                    if([areaStr isEqualToString:@"全部"])
//                    {
//                        return 213;
//                    }else if([areaStr isEqualToString:@"朝阳"]) {
//                        return 211;
//                    }else if([areaStr isEqualToString:@"海淀"]) {
//                        return 212;
//                    }
//                }else if([priceStr isEqualToString:@"999"]){
//                    if([areaStr isEqualToString:@"全部"])
//                    {
//                        return 223;
//                    }else if([areaStr isEqualToString:@"朝阳"]) {
//                        return 221;
//                    }else if([areaStr isEqualToString:@"海淀"]) {
//                        return 222;
//                    }
//                    
//               
//                }  
//    }           

   
}

-(void)setCellArray
{
    
    
    //dic 111
    //dic1 112
    //dic2 222
    //dic3 221
    self.choise=[self getDate];
    [name removeAllObjects];
    [price removeAllObjects];

    if (self.choise==333) {
        [self setCellText:self.searchResultDic111];
        [self setCellText:self.searchResultDic112];
        [self setCellText:self.searchResultDic121];
        [self setCellText:self.searchResultDic122];
        [self setCellText:self.searchResultDic211];
        [self setCellText:self.searchResultDic212];
        [self setCellText:self.searchResultDic221];
        [self setCellText:self.searchResultDic222];
        
    }
    if(self.choise==311){
        [self setCellText:self.searchResultDic111];
        [self setCellText:self.searchResultDic211];
    }
    if(self.choise==312){
        [self setCellText:self.searchResultDic112];
        [self setCellText:self.searchResultDic212];
    }
    if(self.choise==321){
        [self setCellText:self.searchResultDic121];
        [self setCellText:self.searchResultDic221];
    }
    if(self.choise==322){
        [self setCellText:self.searchResultDic212];
        [self setCellText:self.searchResultDic222];
    }
    if(self.choise==313){
        [self setCellText:self.searchResultDic111];
        [self setCellText:self.searchResultDic211];
        [self setCellText:self.searchResultDic112];
        [self setCellText:self.searchResultDic212];
    }
    
    if(self.choise==323){
        [self setCellText:self.searchResultDic121];
        [self setCellText:self.searchResultDic221];
        [self setCellText:self.searchResultDic212];
        [self setCellText:self.searchResultDic222];
    }
    if(self.choise==331){
        [self setCellText:self.searchResultDic111];
        [self setCellText:self.searchResultDic211];
        [self setCellText:self.searchResultDic121];
        [self setCellText:self.searchResultDic221];
    }
    
    if(self.choise==332){
        [self setCellText:self.searchResultDic112];
        [self setCellText:self.searchResultDic212];
        [self setCellText:self.searchResultDic212];
        [self setCellText:self.searchResultDic222];
    }
    if(self.choise==113){
        [self setCellText:self.searchResultDic111];
        [self setCellText:self.searchResultDic112];
    }
    
    if(self.choise==123){
        [self setCellText:self.searchResultDic121];
        [self setCellText:self.searchResultDic122];
 
    }
    if(self.choise==131){
        [self setCellText:self.searchResultDic111];
     
        [self setCellText:self.searchResultDic121];
       
    }
    if(self.choise==132){
        [self setCellText:self.searchResultDic112];
        [self setCellText:self.searchResultDic122];
    }
    if(self.choise==133){
        [self setCellText:self.searchResultDic112];
        [self setCellText:self.searchResultDic122];
        [self setCellText:self.searchResultDic111];
        [self setCellText:self.searchResultDic121];
  
  
    }
    if(self.choise==231){
        [self setCellText:self.searchResultDic211];
        [self setCellText:self.searchResultDic221];
        
    }
    if(self.choise==232){
        [self setCellText:self.searchResultDic212];
        [self setCellText:self.searchResultDic222];
    }
    if(self.choise==213){
        [self setCellText:self.searchResultDic211];
        [self setCellText:self.searchResultDic212];

    }
    if(self.choise==223){
        [self setCellText:self.searchResultDic221];
        [self setCellText:self.searchResultDic222];
    }
    if(self.choise==233){
        [self setCellText:self.searchResultDic221];
        [self setCellText:self.searchResultDic222];
        [self setCellText:self.searchResultDic211];
        [self setCellText:self.searchResultDic212];

      

    }
    
    
    if(self.choise==111){
        [self setCellText:self.searchResultDic111];
    }
    if(self.choise==112){
        [self setCellText:self.searchResultDic112];
    }
    if(self.choise==121){
        [self setCellText:self.searchResultDic121];
    }
    if(self.choise==122){
        [self setCellText:self.searchResultDic122];
    }
    if(self.choise==211){
        [self setCellText:self.searchResultDic211];
    }
    if(self.choise==212){
        [self setCellText:self.searchResultDic212];
    }
    if(self.choise==221){
        [self setCellText:self.searchResultDic221];
    }
    if(self.choise==222){
        [self setCellText:self.searchResultDic222];
    }
    

          
    [self.searchtableView reloadData];
}

-(void)setCellText:(NSMutableDictionary *)tempDic
{
    NSEnumerator* enume= [tempDic keyEnumerator];
    NSLog(@"enume-->>>%@",enume);
    NSString *mykey;
    
    while (mykey= (NSString *)[enume nextObject]) {
        NSMutableDictionary *mydic=[[NSMutableDictionary alloc]init];
        NSLog(@"mykey---->>%@",mykey);
        mydic=(NSMutableDictionary *)[tempDic objectForKey:mykey];
        NSString *string=[NSString stringWithFormat:@"%@ %@",[mydic objectForKey:@"CoureName"],[mydic objectForKey:@"Area"]];
        [self.name addObject:string];
        [self.price addObject:[mydic objectForKey:@"Price"]];
        
        
    }

}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)popover:(UIButton *)sender {
    PopoverTableViewController *controller = [[PopoverTableViewController alloc]init];
    
    controller.choosItem=[[NSMutableArray alloc]init];
    controller.button=sender;
    //controller.popoverController=self;
    
    controller.coursesSearchViewController=self;
    NSLog(@"texttitle=:%@",sender.titleLabel.text);
    NSLog(@"类型=:%@",[self.searchConditions objectForKey:@"coursesType"]);
    if([sender.titleLabel.text isEqualToString:@"类型"])
    {
        NSLog(@"选择了类型");
        controller.choosItem=(NSMutableArray*)[searchConditions objectForKey:@"coursesType"];
    }
    else if([sender.titleLabel.text isEqualToString:@"价格"])
    {
        
        controller.choosItem=(NSMutableArray*)[searchConditions objectForKey:@"coursesPrice"];
    }
    else if([sender.titleLabel.text isEqualToString:@"地区"])
    {
        controller.choosItem=(NSMutableArray*)[searchConditions objectForKey:@"coursesArea"];
    }
    
    
    FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller];
    
    controller.popoverController=[[FPPopoverController alloc]init];
    
    controller.popoverController=popover;
    [controller release];
    
    //popover.arrowDirection = FPPopoverArrowDirectionAny;
    //popover.tint = FPPopoverDefaultTint;
    popover.tint=FPPopoverLightGrayTint;
    
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        popover.contentSize = CGSizeMake(300, 500);
    }
    popover.arrowDirection = FPPopoverArrowDirectionAny;
    
    
    //sender is the UIButton view
    [popover presentPopoverFromView:sender]; 
    
}
- (void)dealloc {
    [searchtableView release];
    [super dealloc];
}



#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [name count];
    //return [nameResult count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }
    //   cell.textLabel.text = [NSString stringWithFormat:@"cell %d",indexPath.row];
//    cell.textLabel.text = [nameResult objectAtIndex:indexPath.row];

    cell.textLabel.text=[self.name objectAtIndex:indexPath.row];
    cell.detailTextLabel.text=[self.price objectAtIndex:indexPath.row];
  

    
    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //button.titleLabel.text=[choosItem objectAtIndex:indexPath.row];
    CoursesDetailViewController *detailViewController=[[CoursesDetailViewController alloc]init];
    [self.navigationController pushViewController:detailViewController animated:YES];
    
}

@end
